execute positioned {cords where the command is executed} as @e[type=villager,tag=npc3,distance=..4] positioned {cords to where the npc is walking} run function ai:pathing/settargetatposition
execute positioned {cords where the command is executed} unless entity @e[type=villager,tag=npc3,distance=..4] run schedule function {this function} 1t